package com.aqie.easy.hash;

import java.util.HashSet;

/**
 * 771. 宝石与石头
 * HashSet      : 无序不可重复元素集合
 * HashMap      : key-value
 * HashTable    : 线性安全, 可被 ConcurrentHashMap
 */
public class NumJewelsInStones {
    public static int numJewelsInStones(String J, String S) {
        int sum = 0;
        HashSet<Character> set = new HashSet<>();
        for (int i = 0; i < J.length(); i++){
            set.add(J.charAt(i));
        }
        for (int i = 0; i < S.length();i++){
            if (set.contains(S.charAt(i))){
                sum++;
            }
        }
        return sum;
    }

    public static void main(String[] args) {
        String J = "aA", S = "aAAbbbb";
        System.out.println(numJewelsInStones(J, S));
    }
}
